package com.company.cloud.page.modules.mgr.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.cloud.common.auth.annotation.Authc;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.page.modules.base.entity.PageCardConfigInfo;
import com.company.cloud.page.modules.cache.models.PageCardModel;
import com.company.cloud.page.modules.cache.models.WebPageComponentConfigModel;
import com.company.cloud.page.modules.cache.models.WebPageComponentModel;
import com.company.cloud.page.modules.cache.models.WebPageConfigModel;
import com.company.cloud.page.modules.mgr.controller.req.*;
import com.company.cloud.page.modules.mgr.service.WebPageConfigMgrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * WEB页面管理
 */
@Authc
@RestController
@RequestMapping("/mgr/cms/webPage")
@Api(tags = "Page_MGR_WEB页面管理")
public class WebPageConfigMgrController {

    @Autowired
    private WebPageConfigMgrService webPageConfigMgrService;

    @PostMapping("/query")
    @ApiOperation(value = "列表查询", response = WebPageConfigModel.class)
    public BaseResult query(@RequestBody WebPageConfigQuery4PageParam params) {
        LoginSimpleUserInfo userInfo = AuthContextUtils.getUser();
        IPage<WebPageConfigModel> data= webPageConfigMgrService.query(params,userInfo);
        return BaseResult.ok(data);
    }

    @PostMapping("/add")
    @ApiOperation(value="新增", response= BaseResult.class)
    public BaseResult add(@RequestBody WebPageConfigAdd2EditParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageConfigMgrService.save(params,userInfo);
        return BaseResult.ok();
    }

    @PostMapping("/edit")
    @ApiOperation(value="修改", response= BaseResult.class)
    public BaseResult edit(@RequestBody WebPageConfigAdd2EditParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageConfigMgrService.update(params,userInfo);
        return BaseResult.ok();
    }


    @GetMapping("/info")
    @ApiOperation(value="查看", response= WebPageConfigModel.class)
    public BaseResult info(@RequestParam("pageNo")String pageNo) {
        WebPageConfigModel data=  webPageConfigMgrService.info(pageNo);
        return BaseResult.ok(data);
    }


    @GetMapping("/del")
    @ApiOperation(value="删除", response= BaseResult.class)
    public BaseResult del(@RequestParam("pageNo")String pageNo) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageConfigMgrService.del(pageNo,userInfo);
        return BaseResult.ok();
    }


    @PostMapping("/upDown")
    @ApiOperation(value="上下架", response= BaseResult.class)
    public BaseResult upDown(@RequestBody WebPageConfigUpDownParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageConfigMgrService.updown(params,userInfo);
        return BaseResult.ok();
    }

    //==========================================================================

    @PostMapping("/pageComponentEdit")
    @ApiOperation(value="页面组件修改", response= WebPageComponentModel.class)
    public  BaseResult pageComponentEdit(@RequestBody WebPageComponentUpdateParam params){
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        WebPageComponentModel data= webPageConfigMgrService.pageComponentUpdate(params,userInfo);
        return BaseResult.ok(data);
    }

    @GetMapping("/pageComponentInfo")
    @ApiOperation(value="页面组件详情", response= WebPageComponentModel.class)
    public BaseResult pageComponentInfo(@RequestParam("pageComponentNo")String pageComponentNo) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        WebPageComponentModel data= webPageConfigMgrService.pageComponentInfo(pageComponentNo);
        return BaseResult.ok(data);
    }

    @GetMapping("/pageComponentDel")
    @ApiOperation(value="页面组件删除", response= BaseResult.class)
    public BaseResult pageComponentDel(@RequestParam("pageComponentNo")String pageComponentNo) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageConfigMgrService.pageComponentDel(pageComponentNo,userInfo);
        return BaseResult.ok();
    }










}
